package com.example.springcloud.consumer.student.configuration;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ClientConfiguration {
    /**
     * 手动注入servlet，用于管理 hystrix.stream
     * 不建议使用此方式，应在配置文件中使用
     * management:
     *   endpoints:
     *     web:
     *       exposure:
     *         include: "hystrix.stream"
     * @return bean
     */
    // @Bean
    @SuppressWarnings("unuse")
    public ServletRegistrationBean<HystrixMetricsStreamServlet> getServlet() {
        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean<HystrixMetricsStreamServlet> registrationBean =
                new ServletRegistrationBean<>( streamServlet);
        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/hystrix.stream" );
        registrationBean.setName("HystrixMetricsStreamServlet" );
        return registrationBean;
    }

}
